﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '修改',
	        iconCls: 'icon-edit',
	        handler: function () {
	            let row = $("#booklist").datagrid("getSelected");
                $("#ff").form('load', row);
                $('#dd').dialog('open');}
	    }, '-', {
	        text: '启用',
	        iconCls: 'icon-ok',
	        handler: function () {
                let row = $("#booklist").datagrid("getSelected");
                $.ajax({
                    type: 'post',
                    url: '/manager/user/modifyStatusEnable',
                    data: {
                        id: row.id
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 2001) {
                            $("#booklist").datagrid('reload');
                        } else if (data.status == 2006) {
                            alert(data.msg);
                        }
                    }
                })
            }
	    }, '-', {
	        text: '禁用',
	        iconCls: 'icon-cancel',
	        handler: function () {
                let row = $("#booklist").datagrid("getSelected");
                $.ajax({
                    type: 'post',
                    url: '/manager/user/modifyStatusDisable',
                    data: {
                        id: row.id
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 2001) {
                            $("#booklist").datagrid('reload');
                        } else if (data.status == 2005) {
                            alert(data.msg);
                        }
                    }
                })
            }
	    }];
	   $(function(){
	       $('#booklist').datagrid({  
				title:'用户列表',  
				iconCls:'icon-save',   
				url:'/manager/user/findAll',
				columns:[
				    [{field: 'id', title: '编号', width: 80, align: 'center'},
					{field:'username',title:'姓名',width:100,align:'center'},
					{field:'phone',title:'电话',width:200,align:'center'},
					{field:'email',title:'email',width:80,align:'center'},
					{field:'flag',title:'状态',width:200,align:'center',
                        formatter: function (value, row, index) {
                            if (value == '-1') {
                                return '禁用';
                            } else if (value == '1') {
                                return '启用';
                            }
                        }
					}
					]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});



		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#booklist').datagrid({
                    url: '/manager/user/findByName',
                    queryParams: form2Json("searchform")
                });   //点击搜索
            });

       //将表单数据转为json
       function form2Json(id) {
           var arr = $("#" + id).serializeArray();
           var jsonStr = "";
           jsonStr += '{';
           for (var i = 0; i < arr.length; i++) {
               jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",';

           }
           jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
           jsonStr += '}';
           var json = JSON.parse(jsonStr)
           return json
       }

          //初始化修改窗口  
         $('#dd').dialog({
			    title: '修改用户',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    // href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        $("#ff").form("submit", {
                            url: '/manager/user/modify',
                            onSubmit: function () {
                                return $(this).form('enableValidation').form('validate');
                            },
                            success: function (data) {
                                var result = eval("(" + data + ")");
                                if (result.status == 2001) {
                                    alert("修改成功")
                                    $("#dd").dialog('close');
                                    $('#booklist').datagrid('reload');
                                }
                            }

                        });
                    }

                },{
                    text:'关闭',
                    handler:function(){
                        $("#dd").dialog('close');
                    }
                }]
			});


            
	   });
	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>用户查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" size=20 placeholder="姓名"/>
        <select name="search_type" id="search_type" >
            <option value="0">请选择状态</option>
            <option value="1" >启用</option>
            <option value="-1">禁用</option>
        </select>
    </td>
	<td>
	  <a id="submit_search">搜索</a>
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post">
                <input type="hidden" name="id"/>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="username" style="width:50%" data-options="label:'姓名:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="phone" style="width:50%" data-options="label:'电话:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="email" style="width:50%" data-options="label:'email:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="interest" style="width:50%;height:60px" data-options="label:'兴趣爱好:',multiline:true">
            </div> 
        </form>
           </div>
    </div>
</body>
</html>